ThreadNum()

General System Function

Syntax samples

THREADNUM()

IF THREADNUM()=215 THEN DEBUG

Description

Every time any logic is executed, it is executed by a thread which is assigned a unique number. THREADNUM returns the number of the thread that called the function. This function is most useful in conjunction with the IF...THEN and DEBUG statements to bring up the debugger at a certain process. See below for a detailed example. Note that if the model does not change between simulation runs, every thread will have the same number from run to run, but not from replication to replication. Also, most changes in a model will cause threads to have different numbers on subsequent runs.

Valid In

Any logic

Example

For example, suppose that when the 50th entity of a certain type arrives at a certain location, the model always crashes. A DEBUG statement at the beginning of the processing logic would be cumbersome because the debugger would come up forty-nine times before it was needed. However, when the error occurs, the debugger displays the process and logic that caused the error, as shown below.

 

By adding the statement, "IF THREADNUM() = 210 THEN DEBUG" before the statement that causes the error, the simulation will run until the proper process and then bring up the debugger. The debugger can then be used to step through the process to find the particular statement causing the error.

See Also

DEBUG.